Completed
Push — master ( e193d1...415e1b )
by Justin
01:32
created

module.exports   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 136

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 136
rs 8.2857

10 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 11 2
A 0 3 1
A 0 3 1
A 0 14 3
A 0 3 1
A 0 4 1
A 0 3 1
A 0 3 1
A 0 4 1
A 0 4 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
module.exports = function(GedcomX){
2
3
  var utils = require('../utils'),
4
      AtomCommon = require('./AtomCommon');
5
  
6
  /**
7
   * Common schema for atom authors and contributors.
8
   * 
9
   * @constructor
10
   * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
11
   */
12
  var AtomPerson = function(json){
13
    
14
    // Protect against forgetting the new keyword when calling the constructor
15
    if(!(this instanceof AtomPerson)){
16
      return new AtomPerson(json);
17
    }
18
    
19
    // If the given object is already an instance then just return it. DON'T copy it.
20
    if(AtomPerson.isInstance(json)){
21
      return json;
22
    }
23
    
24
    this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
25
  };
26
  
27
  AtomPerson.prototype = Object.create(AtomCommon.prototype);
28
  
29
  AtomPerson._gedxClass = AtomPerson.prototype._gedxClass = 'GedcomX.AtomPerson';
30
  
31
  AtomPerson.jsonProps = [
32
    'uri',
33
    'name',
34
    'email'
35
  ];
36
  
37
  /**
38
   * Check whether the given object is an instance of this class.
39
   * 
40
   * @param {Object} obj
41
   * @returns {Boolean}
42
   */
43
  AtomPerson.isInstance = function(obj){
44
    return utils.isInstance(obj, this._gedxClass);
45
  };
46
47
  /**
48
   * Initialize from JSON
49
   * 
50
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
51
   * @return {AtomPerson} this
52
   */
53
  AtomPerson.prototype.init = function(json){
54
    
55
    AtomCommon.prototype.init.call(this, json);
56
    
57
    if(json){
58
      this.setUri(json.uri);
59
      this.setName(json.name);
60
      this.setEmail(json.email);
61
    }
62
    return this;
63
  };
64
  
65
  /**
66
   * Set the uri
67
   * 
68
   * @param {String} uri
69
   * @return {AtomPerson} this
70
   */
71
  AtomPerson.prototype.setUri = function(uri){
72
    this.uri = uri;
73
    return this;
74
  };
75
  
76
  /**
77
   * Get the uri
78
   * 
79
   * @return {String} this
80
   */
81
  AtomPerson.prototype.getUri = function(){
82
    return this.uri;
83
  };
84
  
85
  /**
86
   * Set the name
87
   * 
88
   * @param {String} name
89
   * @return {AtomPerson} this
90
   */
91
  AtomPerson.prototype.setName = function(name){
92
    this.name = name;
93
    return this;
94
  };
95
  
96
  /**
97
   * Get the name
98
   * 
99
   * @return {String} this
100
   */
101
  AtomPerson.prototype.getName = function(){
102
    return this.name;
103
  };
104
  
105
  /**
106
   * Set the email
107
   * 
108
   * @param {String} email
109
   * @return {AtomPerson} this
110
   */
111
  AtomPerson.prototype.setEmail = function(email){
112
    this.email = email;
113
    return this;
114
  };
115
  
116
  /**
117
   * Get the name
118
   * 
119
   * @return {String} this
120
   */
121
  AtomPerson.prototype.getEmail = function(){
122
    return this.email;
123
  };
124
  
125
  /**
126
   * Export the object as JSON
127
   * 
128
   * @return {Object} JSON object
129
   */
130
  AtomPerson.prototype.toJSON = function(){
131
    return this._toJSON(AtomCommon, AtomPerson.jsonProps);
132
  };
133
  
134
  GedcomX.AtomPerson = AtomPerson;
135
136
};